<?php
class queryData {
	var $i = 0;
	var $y = 1;
	
	function unset_session($session_name) {
		$session_name = strip_tags($session_name);
		if (isset($_SESSION[$session_name])) {
			unset($_SESSION[$session_name]);
			return true;
		} else
			return false;
	}
	
	function redirect_page($pagename) {
		$pagename = strip_tags($pagename);
		header("Location:".$pagename);	
	}
	
	function get_curr_dir($filename) {
		chdir($filename);
		$data = str_replace("\\","/",getcwd());
		return $data;
	}
	
	function c_substr($str, $length, $minword = 3) {
		$sub = '';
		$len = 0;
	   
		foreach (explode(' ', $str) as $word) {
			$part = (($sub != '') ? ' ' : '') . $word;
			$sub .= $part;
			$len += strlen($part);
		   
			if (strlen($word) > $minword && strlen($sub) >= $length) {
				break;
			}
		}
		return $sub . (($len < strlen($str)) ? '...' : '');
	}
	
	function tagCloud($stat,$tag,$type,$fieldname,$id,$class='',$style='') {
		global $DEV_TAG_TITLE;
		switch ($stat) {
			case "create" :
				$html = $DEV_TAG_TITLE.' <input name="'.$fieldname.'" id="'.$fieldname.'" value="'.$tag.'" type="text" class="'.$class.'" style="'.$style.'" />';
			break;
			case "input" :
				$sql = "INSERT INTO x_fieldvalue VALUES(NULL,'".$type."','".$fieldname."','".$tag."','".$id."')";
				$qry = mysql_query($sql);
				$html = 'input';
			break;
			case "edit" :
				$row = $this->selek1('x_fieldvalue',"id_user='".$id."' AND tipe='".$type."'");
				if ($row->id_all=="")
					$sql = "INSERT INTO x_fieldvalue VALUES(NULL,'".$type."','".$fieldname."','".$tag."','".$id."')";
				else
					$sql = "UPDATE x_fieldvalue SET fieldvalue='".$tag."' WHERE id_user='".$id."'";
				$qry = mysql_query($sql);
				$html = 'edit';
			break;
			case "hapus" :
				$sql = "DELETE FROM x_fieldvalue WHERE id_user='".$id."'";
				$qry = mysql_query($sql);
				$html = 'hapus';
			break;
			case 'view' :
				$html = '';
				$row = $this->selek1('x_fieldvalue',"id_user='".$id."' AND fieldname='".$fieldname."' AND tipe='".$type."'");
				if ($row->fieldvalue!="") {
					$expl = explode(',',$row->fieldvalue);
					foreach ($expl as $val) {
						$data = trim($val);
						$data = ereg_replace( ' +', ' ', $data);
						$data = mysql_real_escape_string(trim(strip_tags($data)));
						$datax = $data;
						$data = str_replace(' ','+',$data);
						$html .= '<a title="'.$datax.'" href="'.$tag.'?s='.$data.'">'.$datax.'</a>, ';
					}
					$html = substr($html,0,-2);
				}
				$html .= '';
			break;
		}
		return $html;
	}
	
	function generate_uniq() {
		list($usec, $sec) = explode(" ", microtime());
		$data = date("YmdHis").substr(((float)$usec + (float)$sec),0,4);
		return $data;
	}	

	function permalink($idx,$title="",$modul="") {
		if (trim($idx)!="") { $rowQ = $this->selek1("tbl_content","idx='".$idx."' LIMIT 1");
		} elseif ($title!="") { $rowQ->judul = $title;
		} elseif ($modul!="") {
			if (trim(SHOWVIEW)=="") { $rowQ->judul = "Home";
			} else {
				$rowQ = $this->selek1("modul","nama_modul='".$modul."'");
				if ((@$rowQ->url!="") && (@is_file($rowQ->url))) {
					$path = dirname($rowQ->url).'/'; 
					include $path.'langs/'.BASE_LANGUAGE.'.inc.php';
					$rowQ->judul = $MOD_NAME;
				} else $rowQ->judul = "Home";
			}
		} else $rowQ->judul = "Home";
		$rowQ->judul = htmlspecialchars($rowQ->judul);
		$arr1 = array("&amp;","&lt;","&gt;",".","&nbsp;","%20","&quot;","`","\"","\'",";",":",")","(");
		$arr2 = array("_"," ","$","@","&ndash;","*","&"," ","%20","$gt","<");
		$arr3 = array("RETURN","return","NOT","AND","and","not","if","IF","else","ELSE","SELECT");
		$rowQ = str_replace($arr1,'_',$rowQ->judul);
		$rowQ = str_replace($arr2,'-',$rowQ);
		$rowQ = str_replace($arr3,'',$rowQ);
		$rowQ = trim(ereg_replace( ' +', ' ', $rowQ));
		$rowQ = str_replace(' ','+',$rowQ);
		$rowQ = preg_replace('/-+/','-',$rowQ);
		$rowQ = trim(strtolower($rowQ));
		($rowQ!="") ? $rowQ = $rowQ.".html" : $rowQ = "unknown";
		return $rowQ;
	}
	
	function hyperlink(&$text) {
		$arr1 = array("http://","ftp://","//","https://","www","com","co.cc");
		$arr2 = array("http:// ","ftp:// ","https:// ","xxx","cxm","co[dot]cc");
		$text = str_replace($arr1,$arr2,$text);
		return $text;
	}
	
	function permalink_kategori($idx) {
		$rowQ = $this->selek1("ikadir_kat","id_dirkat='".$idx."' LIMIT 1");
		$arr1 = array("&amp;","&lt;","&gt;",".","&nbsp;","%20","&quot;","`","\"","\'",";",":",")","(");
		$arr2 = array("_"," ","$","@","&ndash;","*","&"," ","%20","$gt","<");
		$arr3 = array("RETURN","return","NOT","AND","and","not","if","IF","else","ELSE","SELECT");
		$rowQ = str_replace($arr1,'_',$rowQ->dir_kat);
		$rowQ = str_replace($arr2,'-',$rowQ);
		$rowQ = str_replace($arr3,'',$rowQ);		
		$rowQ = trim(ereg_replace( ' +', ' ', $rowQ));
		$rowQ = str_replace(' ','+',$rowQ);
		$rowQ = preg_replace('/-+/','-',$rowQ);
		$rowQ = strtolower($rowQ);
		($rowQ!="") ? $rowQ = $rowQ.".html" : $rowQ = "unknown";
		return $rowQ;
	}
	
	function link_kategori($idx) {
		$rowQ = $this->selek1("ikadir_kat","id_dirkat='".$idx."'");
		$rowQ = $rowQ->dir_kat;
		return $rowQ;
	}
	
	function selek1($tabel_selek1,$kondisi1,$field="*") {
		$sqlselek1 = "SELECT ".$field." FROM ".$tabel_selek1." WHERE 1 AND ".$kondisi1;
		$qryselek1 = mysql_query($sqlselek1);
		$rowselek1 = mysql_fetch_object($qryselek1);
		return $rowselek1;
	}
	
	function deleteContent($tabel,$qry=1) {
		$sqlQ = "DELETE * FROM ".$tabel." WHERE ".$qry;
		$qryQ = mysql_query($sqlQ);
		
		return $qryQ;
	}
		
	function compile_array($mysql) {
		$i = $this->i;
		while ($field = mysql_fetch_field($mysql)) {
			$fields[$i] = $field->name; $i++;
		}
		$i = $this->i;
		while ($mysql_result = mysql_fetch_array($mysql)) {
			foreach ($fields as $val) {
				$data[$i][$val] = $mysql_result[$val];
			}
			$i++;
		}
		return $data;
	}
	
	function tanggalan($tgl_init,$time=false,$datenumeric=false,$dateshort=false,$with_time=false,$dateonly=false) {
		global $DEV_DAY_OF_WEEK,$DEV_MONTH,$DEV_MONTH_SORT;
		if ((substr($tgl_init,0,10)!="0000-00-00") || ($tgl_init!="0000-00-00 00:00:00")) {
			$c = array(" " ,":");
			$d = "-";
			$tmp_tgl = str_replace($c,$d,$tgl_init);
			$tmp_tgl = explode("-", $tmp_tgl);
			$c = trim($tmp_tgl[1]);
			if ($c<=9) {
				$c = str_replace("0","",$c);
			} else {
				$c = $c;
			}
			$mk_time = @mktime($tmp_tgl[3], $tmp_tgl[4], $tmp_tgl[5], $c, $tmp_tgl[2], $tmp_tgl[0]);
			$array_hari = $DEV_DAY_OF_WEEK;
			$array_bln = $DEV_MONTH;
			$array_bln_sort = $DEV_MONTH_SORT;
			((@date("w", $mk_time)-1)<0) ? $isihari=6 : $isihari = @date("w", $mk_time);
			if ($time==true) $view_tanggal = sprintf("%s, %s %s %d [<b>%s:%s:%s</b>]", ucwords($array_hari[$isihari]), $tmp_tgl[2], ucwords($array_bln[date("n", $mk_time)]), $tmp_tgl[0], $tmp_tgl[3], $tmp_tgl[4], $tmp_tgl[5]);
			elseif ($dateonly==true) $view_tanggal = sprintf("%s",substr($tgl_init,0,10));
			elseif ($dateshort==true) $view_tanggal = sprintf("%s %s %d", $tmp_tgl[2], ucwords($array_bln_sort[date("n", $mk_time)]), $tmp_tgl[0]);
			elseif ($datenumeric==true) $view_tanggal = sprintf("%s-%s-%d", $tmp_tgl[2], $tmp_tgl[1], $tmp_tgl[0]);
			else $view_tanggal = sprintf("%s, %s %s %d", ucwords($array_hari[$isihari]), $tmp_tgl[2], ucwords($array_bln[@date("n", $mk_time)]), $tmp_tgl[0]);
			if ($with_time==true) $view_tanggal .= sprintf(" %s:%s", $tmp_tgl[3], $tmp_tgl[4]);
			unset($tmp_tgl);
		}
		return $view_tanggal;
	}

	function view_xfieldvalue($val,$tipe_tabel,$tipe_form,$fieldnames) {
		$ssz1 = mysql_query("SELECT * FROM x_field WHERE tipe='".$tipe_tabel."' ORDER BY urutan ASC");
		$dd = "";
		$i = $this->i;
		while ($ssz2 = mysql_fetch_object($ssz1)) {
			$arr_find = array(" ","/");
			$arr_replace = array("_","_");
			$name_form = str_replace($arr_find,$arr_replace,strtolower($ssz2->fieldname));
			$ds = explode("|",$ssz2->value_form);
			for ($j=($this->i);$j<count($ds);$j++) {
				$ss = explode("#",$ds[$j]);
				if (($ss[0]==$val) && ($fieldnames==$name_form)) {
					if ($tipe_form=="radio") $fieldvalue = $ss[1]; 
				} else $fieldvalue = $val;
				
			}
			$i++;
		}
		return $fieldvalue;
	}
	
	function showpage($filenya,$numrec,$defshow,$perpage,$pagenya,$otherget="") {
		$pages = $numrec / $perpage;
		$last_page = (int)($numrec / $perpage);
		if ($pages > $last_page) $last_page++;
		$count1 = $defshow - $pagenya;
		$count2 = $defshow + $pagenya;
		$mulai = 1;
		$akhir = $count2;
		if ($count1<1) $mulai =  $pagenya - $defshow;
		if ($mulai<1) $mulai = 1;
		if ($count2>$last_page) $akhir = $last_page;
		for ($i=$mulai;$i<=($pagenya-1);$i++) {
			$pagesblm .= '<li><a href="'.URL_PATH.$filenya.'/'.$i.'/'.$otherget.'">'.$i.'</a></li> ';
		}
		$pageskr = '<li class="currentpage">'.$pagenya.'</li> ';
		for ($i=($pagenya+1);$i<=$akhir;$i++) {
			$pagesdh .= '<li><a href="'.URL_PATH.$filenya.'/'.$i.'/'.$otherget.'">'.$i.'</a></li> ';
		}
		$pagehal = '<li class="halaman">Halaman '.$pagenya.' dari '.$last_page.'</li> ';
		$txawal = '<li class="disablepage">&laquo; Awal</li> ';
		$txakhir = '<li class="disablepage">Akhir &raquo;</li> ';
		if ($pagenya>1) {
			$txsebelum = '<li class="prevpage"><a href="'.URL_PATH.$filenya.'/'.($pagenya-1).'/'.$otherget.'">&#8249; Sebelumnya</a></li>';
			$txawal = '<li class="prevpage"><a href="'.URL_PATH.$filenya.'/1/'.$otherget.'">&laquo; Awal</a></li> ';
		}
		if ($pagenya<$last_page) {
			$txsesudah = '<li class="nextpage"><a href="'.URL_PATH.$filenya.'/'.($pagenya+1).'/'.$otherget.'">Berikutnya &#8250;</a></li>' ;
			$txakhir = '<li class="nextpage"><a href="'.URL_PATH.$filenya.'/'.$last_page.'/'.$otherget.'">Akhir &raquo;</a></li> ';
		}
		$divpage = '<div class="pagination"><ul>'.$pagehal.'</ul><ul>'.$txawal.$txsebelum.$pagesblm.$pageskr.$pagesdh.$txsesudah.$txakhir.'</ul></div>';
		return $divpage;
	}

	function cekAksi($var,$type) { 
		global $DEV_ACTION_ADDED_PREFIX,$DEV_ACTION_ADDED_SUFFIX,$DEV_ACTION_EDITED_PREFIX,$DEV_ACTION_EDITED_SUFFIX,$DEV_ACTION_DELETED_PREFIX,$DEV_ACTION_DELETED_SUFFIX;
		switch ($type) {
			case "add" : 
				$aksi = $DEV_ACTION_ADDED_PREFIX.' '.$var.' '.$DEV_ACTION_ADDED_SUFFIX;
			break;
			case "edit" :
				$aksi = $DEV_ACTION_EDITED_PREFIX.' '.$var.' '.$DEV_ACTION_EDITED_SUFFIX;
			break;
			case "delete" : 
				$aksi = $DEV_ACTION_DELETED_PREFIX.' '.$var.' '.$DEV_ACTION_DELETED_SUFFIX;
			break;
			case "custom" : 
				$aksi = $var;
			break;
		} 
		return $aksi;
	}
	
	function NotificationCheck($arrData=array(),$arrType=array(),$arrStat=array()) {
		foreach ($arrData as $num => $val) {
			switch ($arrType[$num]) {
				case "empty" : 
					(trim($val)=='') ? $cekWarn = $arrStat[$num] : $cekWarn = '';
				break;
				case "numeric" : 
					(trim($val)=='') ? $cekWarn = $arrStat[$num] : $cekWarn = '';
					(!is_numeric($val)) ? $cekWarn = $arrStat[$num] : $cekWarn = '';
				break;
				case "fileImage" :
					(trim($val)=='') ? $cekWarn = $arrStat[$num] : $cekWarn = '';
					$ex = array("jpg","jpeg","png","gif","swf");
					(!in_array($val,$ex)) ? $cekWarn = $arrStat[$num] : $cekWarn = '';
				break;
				case "fileGaleri" :
					(trim($val)=='') ? $cekWarn = $arrStat[$num] : $cekWarn = '';
					$ex = array("jpg","jpeg");
					(!in_array($val,$ex)) ? $cekWarn = $arrStat[$num] : $cekWarn = '';
				break;
				case "fileData" :
					(trim($val)=='') ? $cekWarn = $arrStat[$num] : $cekWarn = '';
					$ex = array("txt","zip","pdf","rar","tar","gz");
					(!in_array($val,$ex)) ? $cekWarn = $arrStat[$num] : $cekWarn = '';
				break;
				case "fileImageSize" :
					(trim($val)=='') ? $cekWarn = $arrStat[$num] : $cekWarn = '';
					($size>=512000) ? $cekWarn = $arrStat[$num].'Max: 500Kb' : $cekWarn = '';
				break;
				case "fileDataSize" :
					(trim($val)=='') ? $cekWarn = $arrStat[$num] : $cekWarn = '';
					($size>=2097152) ? $cekWarn = $arrStat[$num].'Max: 2Mb' : $cekWarn = '';
				break;
				case "sameDir" :
					(trim($val)=='') ? $cekWarn = $arrStat[$num] : $cekWarn = '';
					($subkategori=="SAME") ? $cekWarn = $arrStat[$num] : $cekWarn = '';
				break;
				case "dataemail" :
					(!preg_match('/^[^@]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$/', trim($val))) ? $cekWarn = $arrStat[$num] : $cekWarn = '';
				break;
			}
			(trim($cekWarn)!='') ? $warning[$num] = $cekWarn : "";
		}
		return $warning;
	}


	function x_field($tipe_form="text",$tipe_x_field=NULL,$name_form,$value_form,$custom_x_field,$view_only=false,$css=NULL,$numSS="1",$num_field="1",$numStartArray="0",$visibility="YES",$arrayTH=array()) {
		if ($tipe_x_field=="") {
			switch ($tipe_form) {
				case "text" :
					$val_form[0] = '<input type="text" name="'.$name_form.'" id="'.$name_form.'" value="'.$value_form.'" '.$custom_x_fieldX.'>';
					break;
				case "textarea" :
					$val_form[0] = '<textarea name="'.$name_form.'" id="'.$name_form.'" '.$custom_x_fieldX.'>'.$value_form.'</textarea>';
				break;
			}
		} elseif ($view_only==true) {
			$sqlQ = "SELECT * FROM x_field WHERE tipe='".$tipe_x_field."' AND visible='".$visibility."' ORDER BY urutan ASC";
			$qryQ = mysql_query($sqlQ);
			while ($rowQ = mysql_fetch_object($qryQ)) {
				$arr_find = array(" ","/");
				$arr_replace = array("_","_");
				$name_form = str_replace($arr_find,$arr_replace,strtolower($rowQ->fieldname));
				$tipe_form = $rowQ->tipe_form;
				if ($value_form!="") {
					$dataIsi = $this->selek1("x_fieldvalue","tipe='".$tipe_x_field."' AND fieldname='".$name_form."' AND id_user='".$value_form."'");
					$val_form[1] = $dataIsi->fieldvalue;
				}
				switch ($tipe_form) {
					case "p1" :
						$dataIsi = $this->selek1("propinsi","idx='".$val_form[1]."'");
						$val_form[0] .= "<tr><td valign=\"top\" ".$css.">".$rowQ->fieldname."</td><td valign=\"top\" align=\"center\">:</td><td valign=\"top\">".$dataIsi->nama_propinsi."</td></tr>\n";
					break;
					default :
						$val_form[0] .= "<tr><td valign=\"top\" ".$css.">".$rowQ->fieldname."</td><td valign=\"top\" align=\"center\">:</td><td valign=\"top\">".$val_form[1]."</td></tr>\n";
					break;
				}
			}
		} else {
			$arr_val = $numStartArray;
			$zz = $this->i;
			$sqlQ = "SELECT * FROM x_field WHERE tipe='".$tipe_x_field."' ORDER BY urutan ASC";
			$qryQ = mysql_query($sqlQ);
			while ($rowQ = mysql_fetch_object($qryQ)) {
				($arrayTH[$zz]!="") ? $fieldnamex = $arrayTH[$zz] : $fieldnamex = $row->fieldname;
				if (strtolower($rowQ->visible)==strtolower($visibility)) {
					$arr_find = array(" ","/");
					$arr_replace = array("_","_");
					$name_form = str_replace($arr_find,$arr_replace,strtolower($rowQ->fieldname));
					if (($value_form!="") && (!is_array($value_form))) {
						$dataIsi = $this->selek1("x_fieldvalue","tipe='".$tipe_x_field."' AND fieldname='".$name_form."' AND id_user='".$value_form."'");
						$val_form[1] = $dataIsi->fieldvalue;
					} elseif (is_array($value_form)) {
						$val_form[1] = $value_form[$arr_val];
						$arr_val++;
					}
					$tipe_form = $rowQ->tipe_form;
					$custom_x_fieldX = $rowQ->custom_field." ".$custom_x_field;
					switch ($tipe_form) {
						case "text" :
							$val_form[0] .= "<tr><td valign=\"top\" ".$css.">".$fieldnamex."</td><td valign=\"top\" align=\"center\">:</td><td valign=\"top\"><input type=\"text\" name=\"".$name_form."\" id=\"".$name_form."\" value=\"".$val_form[1]."\" ".$custom_x_fieldX."></td></tr>\n";
						break;
						case "textarea" :
							$val_form[0] .= "<tr><td valign=\"top\" ".$css.">".$fieldnamex."</td><td valign=\"top\" align=\"center\">:</td><td valign=\"top\" style=\"padding-bottom:2px\"><textarea name=\"".$name_form."\" id=\"".$name_form."\" ".$custom_x_fieldX.">".$val_form[1]."</textarea></td></tr>\n";
						break;
						case "radio" :
							$value_formX = explode("|",$rowQ->value_form);
							$numx = $this->i;
							$val_form[0] .= "<tr><td valign=\"top\" ".$css.">".$fieldnamex."</td><td valign=\"top\" align=\"center\">:</td><td valign=\"top\"><table width=300 cellpadding=\"2\" cellspacing=\"2\"><tr>";
							foreach ($value_formX as $num => $isi_x) {
								$isi_xx = explode("#",$isi_x);
								$val_form[0] .= "<td valign=\"top\" nowrap><input name=\"".$name_form."\" id=\"".$name_form."\" type=\"radio\" value=\"".$isi_xx[0]."\" ".$custom_x_fieldX;
								if ($val_form[1]=="") {
									if ($num==$this->i) $val_form[0] .= "checked";
								} elseif ($val_form[1]==trim($isi_xx[0])) $val_form[0] .= "checked";
								$val_form[0] .= " /> ".$isi_xx[1]."</td>";
								$numx++;
								if ($numx>=$numSS) {
									$val_form[0] .= "</tr><tr>";
									$numx = 0;
								}
							}
							$val_form[0] .= "</tr></table></td></tr>\n";
						break;
						case "propinsi" :
							$val_form[0] .= "<tr><td valign=\"top\" ".$css.">".$fieldnamex."</td><td valign=\"top\" align=\"center\">:</td><td valign=\"top\" style=\"padding-bottom:2px\">";
							$val_form[0] .= "<select name=\"".$name_form."\" id=\"".$name_form."\" size=\"1\" ".$custom_x_fieldX.">";
							$sqlD = "SELECT * FROM propinsi ORDER BY nama_propinsi ASC";
							$qryD = mysql_query($sqlD);
							while ($rowD = @mysql_fetch_object($qryD)) {
								$val_form[0] .= "<option value=\"\" style=\"color:#0088FF; font-style:italic; padding-left:5px; font-weight:bold; padding-right:5px\">".$rowD->nama_propinsi."</option>\n";
								$sqlE = "SELECT * FROM kota WHERE id_propinsi='".$rowD->id_propinsi."'";
								$qryE = mysql_query($sqlE);
								$numE = mysql_num_rows($qryE);
								if ($numE) {
									while ($rowE = @mysql_fetch_object($qryE)) {
										$val_form[0] .= "<option";
										if ($rowD->id_propinsi."-".$rowE->nama_kota==$val_form[1]) $val_form[0] .= " selected";
										$val_form[0] .= " value=\"".$rowD->id_propinsi."-".$rowE->nama_kota."\" style=\"color:#000000; font-style:none; padding-right:5px; padding-left:20px;\"><span style=\"font-style:italic\">".$rowD->nama_propinsi."</span> - ".$rowE->nama_kota."</option>\n";
									}
								} else {
									$val_form[0] .= "<option";
									if ($rowD->id_propinsi."-Lainnya"==$val_form[1]) $val_form[0] .= " selected";
									$val_form[0] .= " value=\"".$rowD->id_propinsi."-Lainnya\" style=\"color:#000000; font-style:none;  padding-right:5px; padding-left:20px;\"><span style=\"font-style:italic\">".$rowD->nama_propinsi."</span> - Daerah Lainnya</option>\n";
								}
							}
							$val_form[0] .= "</select>";
							$val_form[0] .= "</td></tr>\n";
						break;
						case "checkbox" :
							$value_formX = explode("|",$rowQ->value_form);
							$numx = $this->i;
							$val_form[0] .= "<tr><td valign=\"top\" ".$css.">".$fieldnamex."</td><td valign=\"top\" align=\"center\">:</td><td valign=\"top\"><table width=\"300\" cellpadding=\"0\" cellspacing=\"0\"><tr>";
							foreach ($value_formX as $isi_x) {
								$isi_xx = explode("#",$isi_x);
								$val_form[0] .= "<td valign=\"top\" nowrap><input name=\"".$name_form."[]\" id=\"".$name_form."[]\" type=\"checkbox\" value=\"".$isi_xx[0]."\" ".$custom_x_fieldX;
								if ($val_form[1]==trim($isi_xx[0])) $val_form[0] .= "checked";
								$val_form[0] .= " /> ".$isi_xx[1]."</td>";
								$numx++;
								if ($numx>=$numSS) {
									$val_form[0] .= "</tr><tr>";
									$numx = $this->i;
								}
							}
							$val_form[0] .= "</tr></table></td></tr>\n";
						break;
						case "select" :
							$val_form[0] .= "<tr><td valign=\"top\" ".$css.">".$fieldnamex."</td><td valign=\"top\" align=\"center\">:</td><td valign=\"top\" style=\"padding-bottom:2px\">";
							$val_form[0] .= "<select id=\"".$name_form."\" name=\"".$name_form."\" size=\"1\" ".$custom_x_fieldX.">";$val_form[0] .= "</select>";
							$val_form[0] .= "</td></tr>\n";
						break;
						case "p1" :
							$val_form[0] .= "<tr><td valign=\"top\" ".$css.">".$fieldnamex."</td><td valign=\"top\" align=\"center\">:</td><td valign=\"top\" style=\"padding-bottom:2px\">";
							$val_form[0] .= "<select id=\"".$name_form."\" name=\"".$name_form."\" onfocus=\"select()\" onkeyup=\"select()\"  onchange=\"select()\" size=\"1\" ".$custom_x_fieldX.">";
							$val_form[0] .= "<option value=\"\">Pilih Propinsi</option>\n";
							$sqlD = "SELECT * FROM propinsi ORDER BY nama_propinsi ASC";
							$qryD = mysql_query($sqlD);
							while ($rowD = @mysql_fetch_object($qryD)) {
								$val_form[0] .= "<option value=\"".$rowD->id_propinsi."\"";
								if ($rowD->id_propinsi==$val_form[1]) $val_form[0] .= " selected";
								$val_form[0] .= ">".$rowD->nama_propinsi."</option>\n";
							}
							$val_form[0] .= "</select>";$val_form[0] .= "</td></tr>\n";
						break;
						case "p2" :
							$val_form[0] .= "<tr><td valign=\"top\" ".$css.">".$fieldnamex."</td><td valign=\"top\" align=\"center\">:</td><td valign=\"top\" style=\"padding-bottom:2px\">";
							$val_form[0] .= "<select id=\"".$name_form."\" name=\"".$name_form."\" size=\"1\" ".$custom_x_fieldX.">";
							$val_form[0] .= "<option value=\"".$val_form[1]."\">".$val_form[1]."</option>\n";
							$val_form[0] .= "</select>";
							$val_form[0] .= "</td></tr>\n";
						break;
					}
				}
				$zz++;
			}
		}
		return $val_form[0];
	}

	function next_prev($num,$pages_syarat,$limitdown) {
		$dataNP = '<table width="200" border="0" align="center" cellpadding="4" cellspacing="0" class="arial11">';
		$dataNP .=  '<tr valign="top" class="bodymid">';
		$dataNP .=  '<th width="150" valign="top" nowrap="nowrap" class="nextprev"><div align="center">';
		if ($limitdown>($this->i)) {
			$dataNP .=  "<a href=\"?show=".SHOW."&showview=".SHOWVIEW."&act=".ACT."&limitdown=".($limitdown-10);
			if (isset($_POST['filter'])) $dataNP .=  "&filter=".$_POST['cari'];
			elseif (isset($pages_syarat)) $dataNP .=  "&" . $pages_syarat;
			$dataNP .=  "\"><img src=\"images/prev.gif\" alt=\"Prev\" border=\"0\"></a>";
		} else {
			$dataNP .=  "<img src=\"images/prev_disable.gif\" alt=\"Next\" border=\"0\">";
		}
		$dataNP .=  '</div></th>';
		$dataNP .=  '<td width="150" valign="top" nowrap="nowrap" class="nextprev"><div align="center">';
		$sub1 = $limitdown-10;
		$sub = $limitdown-$sub1;
		if ($num>$sub) {
			$dataNP .=  "<a href=\"?show=".SHOW."&showview=".SHOWVIEW."&act=".ACT."&limitdown=".($limitdown+10);
			if (isset($_POST['filter'])) $dataNP .=  "&filter=".$_POST['cari'];
			elseif (isset($pages_syarat)) $dataNP .=  "&" . $pages_syarat;
			$dataNP .=  "\"><img src=\"images/next.gif\" alt=\"Next\" border=\"0\"></a>";
		} else $dataNP .=  "<img src=\"images/next_disable.gif\" alt=\"Next\" border=\"0\">";
		$dataNP .=  '</div></td>';
		$dataNP .=  '</tr></table>';
		return $dataNP;
	} 
	
	function chead_tbl_xfield($xfieldtipe,$cssclass,$f1orf2,$customQuery="",$arrayTH=array()) {
		$exclude_table = "";
		$data = "";			
		$i = $this->i;

		if ($f1orf2=='th') {
			$sql = "SELECT * FROM x_field WHERE tipe='".$xfieldtipe."' ORDER BY urutan ASC";
			$qry = mysql_query($sql);
			while ($row = mysql_fetch_object($qry)) {
				($arrayTH[$i]!="") ? $fieldnamex = $arrayTH[$i] : $fieldnamex = $row->fieldname;
				$data .= '<th '.$cssclass.'><div align="center">'.$fieldnamex.'</div></th>';
				$i++;
			}
		} elseif ($customQuery!="") {
			if (is_array($customQuery)) {
				foreach($customQuery as $num => $breakpart) {
					$bpart[$num] = explode("[break]",$breakpart);	
				}
				
				foreach($bpart as $num => $CPART) {
					$sql = $CPART[0];
					$exclude_table .= " AND fieldname!='".$CPART[1]."'";
					$qry = mysql_query($sql);
					$row = mysql_fetch_object($qry);
					switch ($CPART[2]) {
						case "childParent" :
							$sql = "SELECT * FROM x_fieldvalue WHERE id_all='".$row->fieldvalue."'";
							$qry = mysql_query($sql);
							$row = mysql_fetch_object($qry);
						break;
					}
					$data .= '<td><div align="left">'.$row->fieldvalue.'</div></td>';
				}
			}
			$sql = "SELECT * FROM x_field WHERE tipe='".$xfieldtipe."'".$exclude_table." ORDER BY urutan ASC";
			$qry = mysql_query($sql);
			while ($row = mysql_fetch_object($qry)) {
				$arr_find = array(" ","/");
				$arr_replace = array("_","_");
				$name_form = str_replace($arr_find,$arr_replace,strtolower($row->fieldname));
				$sqlA = "SELECT * FROM x_fieldvalue WHERE tipe='".$xfieldtipe."' AND fieldname='".$name_form."' AND id_user='".$f1orf2."'";
				$qryA = mysql_query($sqlA);
				$rowA = mysql_fetch_object($qryA);
				$data .= '<td><div align="left">'.$rowA->fieldvalue.'</div></td>';
			}
		} else {
			$sql = "SELECT * FROM x_field WHERE tipe='".$xfieldtipe."' ORDER BY urutan ASC";
			$qry = mysql_query($sql);
			while ($row = mysql_fetch_object($qry)) {
				$arr_find = array(" ","/");
				$arr_replace = array("_","_");
				$name_form = str_replace($arr_find,$arr_replace,strtolower($row->fieldname));
				$sqlA = "SELECT * FROM x_fieldvalue WHERE tipe='".$xfieldtipe."' AND fieldname='".$name_form."' AND id_user='".$f1orf2."'";
				$qryA = mysql_query($sqlA);
				$rowA = mysql_fetch_object($qryA);
				$data .= '<td><div align="left">'.$rowA->fieldvalue.'</div></td>';
			}
		}
		
		return $data;
	}
	
	function cekModul($userType="",$view_mode="0",$modArray=false) {
		$x = $this->y;
		$userType = explode("[break]",$userType);
		$cekModulku = "";
		foreach ($userType as $uType) {
			if ($uType!="") {
				$sqlQ = "SELECT * FROM tbl_hakakses WHERE tipe='".$uType."'";
				$qryQ = @mysql_query($sqlQ);
				$rowQ = @mysql_fetch_object($qryQ);
				$userTypeX .= "[break]".$rowQ->keterangan;
			}
		}
		$userTypeX = explode("[break]",$userTypeX);
		$sqlQ = "SELECT nama_modul,url,hak_akses,aktivasi,view_mode,urutan FROM `modul` WHERE aktivasi='1' and view_mode='".$view_mode."' ORDER BY urutan ASC";
		$qryQ = mysql_query($sqlQ);
		while ($rowQ = mysql_fetch_object($qryQ)) {
			$url = dirname($rowQ->url).'/langs/'.BASE_LANGUAGE.'.inc.php';
			(is_file($url)) ? include $url : '';
			if (is_array($MOD_NAME)) {
				$MOD_NAME = $MOD_NAME[$x];
			} else $MOD_NAME = $MOD_NAME;
			if (in_array("all",$userTypeX)) {
				$_SESSION['access'][] = $rowQ->nama_modul;
				$cekModulku .= "<li>";$cekModulku .= "<a href=\"index.php?show=admin&amp;showview=".$rowQ->nama_modul."\" title=\"".$rowQ->keterangan."\">".$MOD_NAME.""."</a>";
				$cekModulku .= "</li>";
			} elseif (in_array(($rowQ->nama_modul),$userTypeX)) {
				$_SESSION['access'][] = $rowQ->nama_modul;
				$cekModulku .= "<li>";$cekModulku .= "<a href=\"index.php?show=admin&amp;showview=".$rowQ->nama_modul."\" title=\"".$rowQ->keterangan."\">".$MOD_NAME."</a>";
				$cekModulku .= "</li>";
			}
			$x++;
		}
		return $cekModulku;
	}
		
	function ctrl_data($urldetail='',$urledit='',$urldelete='',$onclickdetail=false,$onclickedit=false,$onclickdelete=true) {
		global $DEV_CTRL_DETAIL,$DEV_CTRL_EDIT,$DEV_CTRL_DELETE,$DEV_CONFIRM_DETAIL,$DEV_CONFIRM_EDIT,$DEV_CONFIRM_DELETE; 
		$data = '<td nowrap="nowrap"><div align="center">';
		if ($urldetail!='') {
			$data .= '<a title="'.$DEV_CTRL_DETAIL.'" href="'.$urldetail.'" ';
			if ($onclickdetail==true) $data .= 'onclick="return conf1(\''.$DEV_CONFIRM_DETAIL.'\')"'; 
			$data .= '><img src="images/detail.png" alt="'.$DEV_CTRL_DETAIL.'" width="16" height="16" border="0" /></a>&nbsp;';
		} 
		if ($urledit!='') {
			$data .= '<a ';
			if ($onclickedit==true) $data .= 'onclick="return conf1(\''.$DEV_CONFIRM_EDIT.'\')" ';
			$data .= 'title="'.$DEV_CTRL_EDIT.'" href="'.$urledit.'"><img src="images/edit.png" alt="'.$DEV_CTRL_EDIT.'" width="16" height="16" border="0" /></a>&nbsp;';
		} 
		if ($urldelete!='') {
			$data .= '<a ';
			if ($onclickdelete==true) $data .= 'onclick="return conf1(\''.$DEV_CONFIRM_DELETE.'\')" '; $data .='title="'.$DEV_CTRL_DELETE.'" href="'.$urldelete.'"><img src="images/delete.png" alt="'.$DEV_CTRL_DELETE.'" title="'.$DEV_CTRL_DELETE.'" width="16" height="16" border="0" /></a>';
		}
		$data .='</div></td>';
		return $data;
	} 

	function cari_form($form_name=NULL) {
		global $DEV_SEARCH,$DEV_CTRL_SEARCH; 
		$form = '<form name="form1" method="post" action="index.php/1/s/?show='.SHOW.'&showview='.SHOWVIEW.'&limitdown=0';
		if (ACT!='') $form .= '&act='.ACT;
		$form .= '"><table border="0" cellspacing="0" cellpadding="4" class="content-arial" align="center"><tr><td><div align="right">'.$DEV_SEARCH.' '.$form_name.' : <input name="cari" type="text" id="cari"><input type="submit" name="submit" value="'.$DEV_CTRL_SEARCH.'"><input name="filter" type="hidden" id="filter" value="true"></div></td></tr></table></form>';
		return $form;
	}
	
	function cari_padaku($tabel1,$tabel2,$custom_query=NULL) {
		global $caridata,$pages_syarat;
		if (isset($_POST['cari'])) {
			$cari = $_POST['cari'];
			$pages_syarat =  "&filter=".$cari;
		} elseif (isset($_GET['filter'])) {
			$cari = $_GET['filter'];
			$pages_syarat = "&filter=".$cari;
		}
		if (((isset($_POST['filter'])) && (!empty($_POST['cari']))) || (isset($_GET['filter']))) {
			if ($custom_query!="") {
				$custom_query = str_replace("[cari]",$cari,$custom_query);
				$caridata = $custom_query;
			} else {
				$caridata = "AND (".$tabel1." LIKE '%".$cari."%' OR ".$tabel2." LIKE '%".$cari."%')";
			}
		}
		return $caridata;
	}
	
	function baseConfig() {
		$sql = "SELECT * FROM config";
		$qry = mysql_query($sql);
		while ($row = mysql_fetch_object($qry)) {
			define($row->configname,$row->value);
		}
	}
	
	function cekJavascript() {
		$data = '<noscript>Your Browser doesn\'t Support Javascript. Please use another Browser (Firefox, Internet Explorer 7++, Google Chrome, Netscape)to make aidiCMS works. Thank You.</noscript>';
		return $data;
	}
		
	function cek_log($ses,$titlenya="") {
		$sql = "SELECT * FROM tbl_log WHERE deskripsi='".$ses."' AND author='sesi'";
		$qry = mysql_query($sql);
		$num = mysql_num_rows($qry);
		if (!$num) {
			if ($titlenya=="") $title = "User Browsing from ".$_SERVER['REMOTE_ADDR'];
			else $title = $titlenya;
			$sql = "INSERT INTO tbl_log VALUES('','".$title."','".$ses."','sesi','".date("Y-m-d-H-i-s")."')";
			$qry = mysql_query($sql);
		}
	}		
	
	function cekUser($ss,$nn=false) {
		if ($nn==false) {
			$sqlQ = "SELECT * FROM tbl_login WHERE namauser='".$ss."'";
		} else {
			$sqlQ = "SELECT * FROM tbl_login WHERE id_user='".$ss."'";	
		}
		$qryQ = mysql_query($sqlQ);
		$rowQ = mysql_fetch_object($qryQ);
		if (empty($rowQ->id_user)) {
			$d = "No Name";	
		} else {
			$d = $rowQ->alias;
		}
		return $d;
		@mysql_free_result($qryY);
	}
	
	function createXMLsitemap() {
		$targetIndex = (defined('USE_REWRITE')) ? USE_REWRITE : "index.php";
		$sql = "SELECT * FROM tbl_content WHERE tipe='berita' OR tipe='artikel' OR tipe LIKE 'dinamis-%'";
		$qry = mysql_query($sql);
		$data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
		$data .= "<urlset\n";
      	$data .= "      xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n";
		$data .= "      xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
		$data .= "      xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n";
		$data .= "            http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">\n";
		$data .= "<url>\n";
		$data .= "  <loc>http://".$_SERVER["HTTP_HOST"]."/</loc>\n";
		$data .= "  <changefreq>monthly</changefreq>\n";
		$data .= "  <priority>1.00</priority>\n";
		$data .= "</url>\n";
		while ($row = mysql_fetch_object($qry)) {
			$priority = mt_rand(10,99);
			(($row->tipe=='berita') || ($row->tipe=='artikel')) ? $cat = 'detail' : $cat = 'dinamis';
			$data .= "<url>\n";
			$data .= "  <loc>http://".$_SERVER["HTTP_HOST"]."/".$targetIndex."/1/".$cat."/".$row->idx."/".$this->permalink($row->idx)."/</loc>\n";
			$data .= "  <changefreq>monthly</changefreq>\n";
			$data .= "  <priority>0.".$priority."</priority>\n";
			$data .= "</url>\n";
		}
		$data .= "</urlset>\n";	
		return $data;
	}
	
	function access_update($idname,$author,$DEV_ACCESS_ATTEMPT) {
		if (is_numeric($idname)) {
			$data = $this->selek1("tbl_log","logx='konten-".$idname."'");
			(!$data->idx) ? $sql = "INSERT INTO tbl_log VALUES(NULL,'konten-".$idname."',1,'".$author."','".date("Y-m-d H:i:s")."')" : $sql = "UPDATE tbl_log SET deskripsi=deskripsi+1,author='".$author."' WHERE logx='konten-".$idname."'";
			$qry = mysql_query($sql);
			$data = $this->selek1("tbl_log","logx='konten-".$idname."'");
		}
		$data = str_replace("[sum]",(int)$data->deskripsi,$DEV_ACCESS_ATTEMPT);
		return $data;
	}
	

}
?>